﻿namespace LS.Nc6.Web.Entry.Areas.Cms.Controllers
{
    /// <summary>
    ///  栏目
    /// </summary>
    [Route("[area]/[controller]/[action]")]
    [Area("Cms")]
    [ApiDescriptionSettings("Default")]
    public class ChannelController : BaseAdminController
    {
        #region CmsContentController
        private readonly ICmsChannelService _channelService;
        private readonly ICmsContentService _contentService;
        private readonly ICmsChannelGroupService _channelGroupService;
        private readonly ICmsContentCheckService _contentCheckService;
        private readonly ISysFileService _fileService;
        private readonly ICache _cache;
        public ChannelController(ICmsChannelService channelService, ICmsContentService contentService, ICmsChannelGroupService channelGroupService, ISysFileService fileService, ICmsContentCheckService contentCheckService,IOptions<CacheOptions> cacheOptions, Func<string, ISingleton, object> resolveNamed)
            :base(cacheOptions, resolveNamed)
        {
            _channelService = channelService;
            _contentService = contentService;
            _channelGroupService = channelGroupService;
            _fileService = fileService;
            _contentCheckService = contentCheckService;
            _cache = resolveNamed(cacheOptions.Value.CacheType.ToString(), default) as ICache;
        }
        #endregion

        #region 页面
        public ActionResult Index()
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_SELECT, UserInfo.ID.ToString());
            ViewBag.AuthUpdate= SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_UPDATE, UserInfo.ID.ToString(), false)?1:0;
            ViewBag.AuthDelete = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_DELETE, UserInfo.ID.ToString(), false) ? 1 : 0;

            ViewBag.AuthAll = (ViewBag.AuthUpdate == 0 && ViewBag.AuthDelete == 0) ? 1 : 0;
            return View();
        }
        public ActionResult Create()
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_SELECT, UserInfo.ID.ToString());

            return View();
        }
        public async Task<ActionResult> Edit(int id)
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_UPDATE, UserInfo.ID.ToString());
            var model = await _channelService.GetByIdAsync(id);
            if (model == null)
            {
                return ErrorCustomMsg(ResponseHelper.NONEXISTENT);
            }
            var channelGroups= await _channelGroupService.List(a => true, a => a.Taxis);
            List<Hashtable> hsChannelGroup = new List<Hashtable>();
            var grouplist = CommonUtil.GetStringListNoNull(model.GroupNames);
            foreach (var item in channelGroups)
            {
                Hashtable hs = new Hashtable();
                hs.Add("GroupName", item.GroupName);
                hs.Add("Checked",RequestHelper.Contains<string>(grouplist,item.GroupName.ToString())?"1":"0");
                hsChannelGroup.Add(hs);
            }
            ViewBag.GroupNamesList = hsChannelGroup;
            //linktype

            ViewBag.LinkTypeList = typeof(LinkType).EnumToList();

            ViewBag.FileImagList =await _fileService.CustomerFileList(model.ImageUrlIds);

            return View(model);
        }

        public async Task<ActionResult> Group(string id)
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_MORE, UserInfo.ID.ToString());
            var channelGroups = await _channelGroupService.List(a => true, a => a.Taxis);
            ViewBag.GroupNamesList = channelGroups;
            ViewBag.Ids = id;
            return View();
        }

        public ActionResult Translate()
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_MORE, UserInfo.ID.ToString());
            return View();
        }

        public ActionResult Taxis(string id)
        {
            SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_TAXIS, UserInfo.ID.ToString());
            ViewBag.Ids = id;
            return View();
        }
        #endregion

        #region  公共方法
        [HttpGet]
        public async Task<ResponseResultDataList> GetList()
        {
            string keyword = RequestHelper.FilterParam(Request.Query["title"]);

            var page = Request.Query["page"].ToString().GetQueryValueOrNull<int>(1);
            var limit = Request.Query["limit"].ToString().GetQueryValueOrNull<int>(20);
            string field = Request.Query["field"];
            string order = Request.Query["order"];

            var expable = Expressionable.Create<CmsChannelEntity>();
            expable.AndIF(!string.IsNullOrEmpty(keyword), a => a.ChannelName.Contains(keyword));

            var exp = expable.ToExpression();
            var strField = RequestHelper.FilterParam(field);
            var strOrder = RequestHelper.FilterParam(order);

            Expression<Func<CmsChannelEntity, object>> expressionOrder;
            if (string.IsNullOrEmpty(strField) || string.IsNullOrEmpty(strOrder))
            {
                expressionOrder = a => new { a.CreateDate };
            }
            else
            {
                //实现字段排序
                expressionOrder = a => new { a.CreateDate };
            }
            var result = await _channelService.PageDynamicList(exp, page, limit, true,expressionOrder, a => new {
                id = a.Id,
                title = a.ChannelName,
                indexName =a.IndexName,
                createDate = a.CreateDate,
                groupNames = a.GroupNames
            });
         
            return new ResponseResultDataList { code = ResponseHelper.SEUCCESSCODE, message = "请求成功", data = result.Item1, count = result.Item2 };
            
        }

        /// <summary>
        /// 获取所有栏目
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResponseResultDataList> GetAll()
        {
            string channelName = RequestHelper.FilterParam(Request.Query["channelName"]);
            string indexName = RequestHelper.FilterParam(Request.Query["indexName"]);
            string groupNames = RequestHelper.FilterParam(Request.Query["groupNames"]);
            List<Hashtable> lsetm = new List<Hashtable>();

            var expable = Expressionable.Create<CmsChannelEntity>();
            expable.AndIF(!string.IsNullOrEmpty(channelName), a => a.ChannelName.Contains(channelName));
            expable.AndIF(!string.IsNullOrEmpty(indexName), a => a.IndexName == indexName);
            expable.AndIF(!string.IsNullOrEmpty(groupNames), a => a.GroupNames.Contains(groupNames));
            var exp = expable.ToExpression();
            var menulist = await _channelService.List(exp,a=>a.Taxis);
            foreach (var item in menulist)
            {
                Hashtable etm = new Hashtable();
                etm.Add("id", item.Id);
                etm.Add("name", item.ChannelName);
                etm.Add("indexName", item.IndexName);
                etm.Add("pId", item.ParentId);
                etm.Add("open", true);
                etm.Add("groupNames", item.GroupNames);
               
                lsetm.Add(etm);
            }
            return new ResponseResultDataList { code = ResponseHelper.SEUCCESSCODE, message = "请求成功", data = lsetm, count = 200 };
        }

        [HttpGet]
        public async Task<ResponseResultDataList> GetChannleCascader()
        {
            string channelId = RequestHelper.FilterParam(Request.Query["channelId"]);

            var data =await GetChannleCascaderData(channelId);
            return new ResponseResultDataList { code = ResponseHelper.SEUCCESSCODE, message = "请求成功", data = data, count = 200 };
        }

        [HttpGet]
        public async Task<dynamic> GetChannelDtree()
        {
            return new
            {
                code = 0,
                msg = "操作成功",
                data = await GetDTreeAllData()
            };
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseResult> SaveData([FromBody] ChannelEditInput input)
        {
            bool power = true;
            long result = 0;
            if (input.Id > 0)
            {
                power = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_UPDATE, UserInfo.ID.ToString(), false);
                if (!power)
                {
                    return ResponseHelper.MessageResult(ResponseHelper.PERMISSION_QXZU);
                }
                var editmodel = await _channelService.GetByIdAsync(input.Id);
                CommonMethodHelper.MapperToModel(editmodel, input, null);

                result = await _channelService.UpdateAsync(editmodel);
            }
            await _cache.DelByPatternAsync("ChannelData");
            return ResponseHelper.SaveResult(result);
        }


        /// <summary>
        /// 新增数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseDataResult> SaveInsertData([FromBody] ChannelInput input)
        {
            ResponseDataResult rdr = new ResponseDataResult();
            rdr.code = 0;
            rdr.message = "保存成功";
            
            bool power = true;

            power = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_ADD, UserInfo.ID.ToString(), false);
            if (!power)
            {
                rdr.code = 1;
                rdr.message = ResponseHelper.PERMISSION_QXZU;
                return rdr;
            }
            var parent = await _channelService.GetByIdAsync(input.ParentId);
            if (parent == null) {
                rdr.code = 1;
                rdr.message = ResponseHelper.PARAMETER_WFQDFLM;
                return rdr;
            }

            var insertedChannelIdHashtable = new Hashtable { [1] = input.ParentId }; //key为栏目的级别，1为第一级栏目

            var channelNames = RequestHelper.GetStringListByReturnAndNewline(input.Channels);
            List<long> expandedChannelIds = new List<long>();

            IList<string> nodeIndexNameList = null;
            foreach (var item in channelNames)
            {
                if (string.IsNullOrEmpty(item)) continue;

                //count为栏目的级别
                var count = RequestHelper.GetStartCount('－', item) == 0 ? RequestHelper.GetStartCount('-', item) : RequestHelper.GetStartCount('－', item);
                var channelName = item.Substring(count, item.Length - count);
                var indexName = string.Empty;
                count++;

                if (!string.IsNullOrEmpty(channelName) && insertedChannelIdHashtable.Contains(count))
                {
                    if (input.IsIndexName ==1)
                    {
                        indexName = channelName.Trim();
                    }

                    if (channelName.Contains('(') && channelName.Contains(')'))
                    {
                        var length = channelName.IndexOf(')') - channelName.IndexOf('(');
                        if (length > 0)
                        {
                            indexName = channelName.Substring(channelName.IndexOf('(') + 1, length);
                            channelName = channelName.Substring(0, channelName.IndexOf('('));
                        }
                    }
                    channelName = channelName.Trim();
                    indexName = indexName.Trim(' ', '(', ')');
                    if (!string.IsNullOrEmpty(indexName))
                    {
                        if (nodeIndexNameList == null)
                        {
                            nodeIndexNameList = await _channelService.GetIndexNames();
                        }
                        if (nodeIndexNameList.Contains(indexName))
                        {
                            indexName = string.Empty;
                        }
                        else
                        {
                            nodeIndexNameList.Add(indexName);
                        }
                    }

                    var parentId = (long)insertedChannelIdHashtable[count]; 

                    var insertedChannelId = await InsertAsync(parentId, channelName, indexName);
                    insertedChannelIdHashtable[count + 1] = insertedChannelId;
                    expandedChannelIds.Add(insertedChannelId);

                   
                }
            }

            rdr.data = expandedChannelIds;
            return rdr;
        }

        [HttpPost]
        public async  Task<ResponseResult> Delete([FromBody]DeletDataInput input)
        {
            var r = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_DELETE, UserInfo.ID.ToString(), false);
            if (!r)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PERMISSION_WSCQX);
            }
            if (string.IsNullOrEmpty(input.Ids))
            {
                return ResponseHelper.MessageResult(ResponseHelper.PARAMETER_CSCW);
            }
            int result =await _channelService.DeleteAsync(input.Ids.ToString());
            return ResponseHelper.DeleteResult(result);
        }

        /// <summary>
        /// 设置栏目分组
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public  async Task<ResponseResult> SettingGroup([FromBody] ChannelGroupInput input)
        {
            if (input == null || input.ChannelIds.Count() == 0)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PARAMETER_CSCW);
            }
            
            var r = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_MORE, UserInfo.ID.ToString(), false);
            if (!r)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PERMISSION_QXZU);
            }
            var channelGroupList= await _channelGroupService.List(a=>true,a=>a.Taxis);
            if(channelGroupList==null || channelGroupList.Count == 0)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PARAMETER_CSCW);
            }
            var allGroupNames = channelGroupList.Select(a => a.GroupName).ToList();
            foreach (var channelId in input.ChannelIds)
            {
                var channel = await _channelService.GetByIdAsync(channelId);
                if (channel == null) continue;

                var list = new List<string>();
                foreach (var groupNames in CommonUtil.GetStringList(channel.GroupNames))
                {
                    if (allGroupNames.Contains(groupNames))
                    {
                        list.Add(groupNames);
                    }
                }

                foreach (var name in input.GroupNames)
                {
                    if (input.GroupType==0)
                    {
                        if (list.Contains(name)) list.Remove(name);
                    }
                    else
                    {
                        if (!list.Contains(name)) list.Add(name);
                    }
                }
                channel.GroupNames =string.Join(",", list);

                await _channelService.UpdateAsync(channel);
            }
            return ResponseHelper.OperateResult(1);
        }

        /// <summary>
        /// 栏目转移
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseResult> SetTranslate([FromBody] ChannelTranslateInput input)
        {
            if (input == null || input.ChannelIds.Count() == 0)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PARAMETER_CSCW);
            }

            var r = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_MORE, UserInfo.ID.ToString(), false);
            if (!r)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PERMISSION_QXZU);
            }

            var channelIdList = new List<long>();//需要转移的栏目ID
            foreach (var channelId in input.ChannelIds)
            {
                if (input.TranslateType != 0)//需要转移栏目
                {
                    if (!await _channelService.IsAncestorOrSelfAsync(channelId, input.TargetChannelId))
                    {
                        channelIdList.Add(channelId);
                    }
                }

                if (input.TranslateType == 0)//转移内容
                {
                    await TranslateContent( channelId, input.TargetChannelId, input.IsDeleteAfterTranslate);
                }
            }
            if (input.TranslateType != 0)//需要转移栏目
            {
                var channelIdListToTranslate = new List<long>(channelIdList);
                foreach (var channelId in channelIdList)
                {
                    var subChannelIdList = await _channelService.GetChannelIdsAsync(channelId,3);

                    if (subChannelIdList != null && subChannelIdList.Count > 0)
                    {
                        foreach (var channelIdToDelete in subChannelIdList)
                        {
                            if (channelIdListToTranslate.Contains(channelIdToDelete))
                            {
                                channelIdListToTranslate.Remove(channelIdToDelete);
                            }
                        }
                    }
                }

                var nodeInfoList = new List<CmsChannelEntity>();
                foreach (var channelId in channelIdListToTranslate)
                {
                    var nodeInfo = await _channelService.GetByIdAsync(channelId);
                    nodeInfoList.Add(nodeInfo);
                }

                await TranslateChannelAndContent(nodeInfoList,input.TargetChannelId, input.TranslateType, input.IsDeleteAfterTranslate);

                if (input.IsDeleteAfterTranslate==1)
                {
                    foreach (var channelId in channelIdListToTranslate)
                    {
                        await _channelService.DeleteAsync(channelId.ParseToString());
                    }
                }
            }
            return ResponseHelper.OperateResult(1);
        }

        /// <summary>
        /// 栏目调整顺序
        /// </summary>
        /// <param name="channelId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResponseResult> SettingTaxis([FromBody] ChannelGroupTaxisInput input)
        {
            if (input == null || input.ChannelIds.Count()==0)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PARAMETER_CSCW);
            }
            var r = SysPower(SysMenuConstant.MENU_CMS_NEWS_LMGL, SysMenuConstant.FUN_MORE, UserInfo.ID.ToString(), false);
            if (!r)
            {
                return ResponseHelper.MessageResult(ResponseHelper.PERMISSION_QXZU);
            }
            var expendedChannelIds = new List<long>();
            foreach (var channelId in input.ChannelIds)
            {
                for (var num = 0; num < input.Taxis; num++)
                {
                    var channel = await _channelService.GetByIdAsync(channelId);
                    if (!expendedChannelIds.Contains(channel.ParentId.Value))
                    {
                        expendedChannelIds.Add(channel.ParentId.Value);
                    }
                    await _channelService.UpdateTaxis(channel.ParentId.Value, channelId, input.IsUp);
                }
            }
            return ResponseHelper.OperateResult(1);
        }

        #endregion

        #region 私有方法
        private  async Task<long> InsertAsync(long parentId,string channelName, string indexName)
        {
            var channelEntity = new CmsChannelEntity
            {
                ParentId = parentId,
                ChannelName = channelName,
                IndexName = indexName,
              
            };
            var parentChannel = await _channelService.GetByIdAsync(parentId);
            if (parentChannel != null)
            {
                channelEntity.ParentsPath = parentChannel.ParentsPath == null
                    ? parentChannel.Id.ToString()
                    : parentChannel.ParentsPath+","+ parentChannel.Id.ToString();

                channelEntity.ParentsCount = parentChannel.ParentsCount + 1;

                var maxTaxis = await _channelService.GetMaxTaxis(channelEntity.ParentId.Value);
                if (maxTaxis == 0)
                {
                    maxTaxis = parentChannel.Taxis.Value;
                }
                channelEntity.Taxis = maxTaxis + 1;
            }
            else
            {
                channelEntity.Taxis = 1;
            }

            channelEntity.ChildrenCount = 0;
            channelEntity.LinkType = LinkType.None.ToString();
            long channelId = await _channelService.InsertAsync(channelEntity);

            if (parentChannel != null)
            {
                await _channelService.UpdateChildrenCount(parentChannel.Id);
            }
            await _cache.DelByPatternAsync("ChannelData");
            return channelId;
        }


        private async Task<List<ChannerlCascModel>> GetChannleCascaderData(string channelId)
        {
            List<ChannerlCascModel> lsetm = new List<ChannerlCascModel>();
            if (_cache.Get<List<ChannerlCascModel>>("ChannelData" ) != null && _cache.Get<List<ChannerlCascModel>>("ChannelData").Count > 0)
            {
                lsetm = _cache.Get<List<ChannerlCascModel>>("ChannelData");
            }
            else
            {
                List<CmsChannelEntity> channellist = await _channelService.List(a => true, a => a.Taxis);

                
                if (channellist != null)
                {
                    var channelhomelist = channellist.Where(w => w.ParentId == 0);
                    foreach (var item in channelhomelist)
                    {
                        ChannerlCascModel etm = new ChannerlCascModel();
                        etm.value = item.Id.ToString();
                        etm.label = item.ChannelName;
                        etm.disabled = false;
                        GetChildren(etm, channellist, item.Id);
                        lsetm.Add(etm);
                    }
                }
              await  _cache.SetAsync("ChannelData", lsetm);
            }
            return lsetm;

        }

        private void GetChildren(ChannerlCascModel etm, List<CmsChannelEntity> listpartmenu, long pid)
        {
            var children = listpartmenu.Where(w => w.ParentId == pid);
            List<ChannerlCascModel> lsetm = new List<ChannerlCascModel>();
            if (children != null && children.Count() > 0)
            {
                foreach (var item in children)
                {
                    ChannerlCascModel etmchildren = new ChannerlCascModel();
                    etmchildren.value = item.Id.ToString();
                    etmchildren.label = item.ChannelName;
                    etmchildren.disabled = false;
                    GetChildren(etmchildren, listpartmenu, item.Id);
                    lsetm.Add(etmchildren);
                }
                if (lsetm.Count > 0)
                {
                    etm.children = lsetm;
                }
            }
        }


        /// <summary>
        /// 树形数据
        /// </summary>
        /// <returns></returns>
        private async Task<List<Hashtable>> GetDTreeAllData()
        {
            List<Hashtable> lsetm = new List<Hashtable>();
            List<CmsChannelEntity> channellist = await _channelService.List(it => true, it => new { it.Id });
            foreach (var item in channellist)
            {
                Hashtable etm = new Hashtable();
                etm.Add("id", item.Id.ToString());
                etm.Add("parentId", item.ParentId);
                etm.Add("title", item.ChannelName.ToString());
                etm.Add("checkArr", "0");
                lsetm.Add(etm);
            }
            return lsetm;
        }

        /// <summary>
        /// 转移内容
        /// </summary>
        /// <param name="channelId"></param>
        /// <param name="targetChannelId"></param>
        /// <param name="isDeleteAfterTranslate"></param>
        /// <returns></returns>
        private async Task TranslateContent( long channelId, long targetChannelId, int isDeleteAfterTranslate)
        {
            var contentIdList = await _contentService.GetContentIdsAsync(channelId);
            contentIdList.Reverse();
            foreach (var contentId in contentIdList)
            {
                await TranslateChannelContent( channelId, contentId, targetChannelId, isDeleteAfterTranslate);
            }
        }

        private  async Task TranslateChannelContent(long channelId, long contentId, long targetChannelId, int translateType)
        {
            if ( channelId <= 0 || contentId <= 0 ||  targetChannelId <= 0) return;

            //var targetChannelInfo = await _channelService.GetByIdAsync(targetChannelId);

            //var channel = await _channelService.GetByIdAsync(channelId);

            var contentInfo = await _contentService.GetByIdAsync(contentId);

            if (contentInfo == null) return;

            if (translateType == 0)
            {
                CmsContentEntity newContent = new CmsContentEntity();
                CommonMethodHelper.MapperToModel(newContent, contentInfo, null);
                newContent.ChannelId = targetChannelId;
                newContent.Taxis = 0;
                newContent.Id = 0;
                var theContentId = await _contentService.InsertAsync(newContent);

                //如果有审核直接复制审核记录
                var  contentCheckList =  await _contentCheckService.GetContentCheck(channelId, contentId);
                foreach (var item in contentCheckList)
                {
                    CmsContentCheckEntity newContentCheck = new CmsContentCheckEntity();
                    CommonMethodHelper.MapperToModel(newContentCheck, item, null);
                    newContentCheck.ChannelId = targetChannelId;
                    newContentCheck.ContentId = theContentId;
                    newContentCheck.Id = 0;
                    //item.ChannelId = targetChannelId;
                    //item.ContentId = theContentId;
                    await _contentCheckService.InsertAsync(newContentCheck);
                }
            }
            else if (translateType == 1)
            {
                contentInfo.ChannelId = targetChannelId;
                contentInfo.Taxis = 0;
                await _contentService.UpdateAsync(contentInfo);
            }
        }


        private async Task TranslateChannelAndContent(List<CmsChannelEntity> nodeInfoList, long parentId, int channelTranslateType, int isDeleteAfterTranslate)
        {
            if (nodeInfoList == null || nodeInfoList.Count == 0)
            {
                return;
            }

            foreach (var nodeInfo in nodeInfoList)
            {
                nodeInfo.ParentId = parentId;
                nodeInfo.ChildrenCount = 0;
                nodeInfo.CreateDate = DateTime.Now;
              
                var targetChannelId = await _channelService.InsertAsync(nodeInfo);

                if (channelTranslateType == 2)
                {
                    await TranslateContent(nodeInfo.Id, targetChannelId, isDeleteAfterTranslate);
                }

                if (targetChannelId != 0)
                {

                    var channelIdList = await _channelService.GetChannelIdsAsync(nodeInfo.Id,2);
                    var childrenNodeInfoList = new List<CmsChannelEntity>();
                    foreach (var channelId in channelIdList)
                    {
                        childrenNodeInfoList.Add(await _channelService.GetByIdAsync(channelId));
                    }

                    if (channelIdList.Count > 0)
                    {
                        await TranslateChannelAndContent(childrenNodeInfoList, targetChannelId, channelTranslateType, isDeleteAfterTranslate);
                    }
                }
            }
        }
        #endregion
    }
}